package create

import (
	"encoding/json"
	"fmt"
	"github.com/urfave/cli/v2"
	"gluenet/internal/client/util"
)

type RequestInstance struct {
	Name          string `json:"name"`
	ConfigId      string `json:"config_id"`
	InstanceLabel string `json:"instance_label"`
}

func instance(ctx *cli.Context) error {
	requestInstance := RequestInstance{
		Name:          ctx.String("name"),
		ConfigId:      ctx.String("config"),
		InstanceLabel: ctx.String("label"),
	}
	reqBody, _ := json.Marshal(requestInstance)

	resp, err := util.HttpRequest("POST", cliUrl+"/apis/instance/create", reqBody)
	if err != nil {
		return err
	}
	fmt.Println(string(resp))
	fmt.Println("Succeed")

	// TODO unable to specify this function

	return nil
}
